define(['playerWithGamepad.m', 'lib/gamepad', 'menu.m'], 
	function(PlayerManager, GamepadManager, MenuManager) {

		/*Define 'core/boilerplate' dependency to access Boilerplate*/
		// Boilerplate.help();

	    var Game = function(Config) {
			/*Construct Game Controler*/
			this.stop = false;
			this.currentTime = +new Date();
			this.secondsElapsed = 0;
			this.parent = Config.parent !== undefined ? Config.parent : false;
		}

		Game.prototype = {
			init : function() {
				/*Initialize game managers*/
				// If configuration allow gamepad usage
				if(this.parent.conf.gamepad.enabled === true) {
					// Initialize as many pad as defined in the configuration
					GamepadManager.init(this.parent.conf.gamepad.count);
					GamepadManager.help();
				} 
				MenuManager.init('HTML');
				PlayerManager.init(this.parent.conf.gamepad.count);

				// Register Events
				var parent = this.parent;
				var input = parent.mInput;
				var canvas = parent.scene.canvas;
				input.registerEvent(canvas, 'tap', function() { MenuManager.functions.Pause(); });
				input.registerEvent(canvas, 'tap', function() { log('Tap 2'); });				
			},
			update : function() {
				/* Update time */
				if (interval(this.currentTime, 1)) {
					this.currentTime = +new Date();
					this.secondsElapsed++;
				}

				debug('Game is running since '+this.secondsElapsed+' seconds');

				// If configuration allow gamepad usage
				if(this.parent.conf.gamepad.enabled === true) {
					// Update the manager
					GamepadManager.update();
				}
				
				/*Game loop - Update game managers*/
				PlayerManager.update();
				MenuManager.update();
			},
			render : function() {				
				// Render Scene
				drawRect(this.parent.scene.ctx,"rgba(0,0,0,.8)",0,0,this.parent.scene.width,this.parent.scene.height);

				PlayerManager.render();
				MenuManager.render();
			},
			gameOver : function() {
				this.stop = true;
			}
		}

		// Save Managers
		for(var iA = 0, cA = arguments.length; iA < cA; iA++) {
			// Get alias for argument
			var argument = arguments[iA];
			// Has model so is manager
			if(argument.model !== undefined) {
				var model = argument.model.prototype.name;
				Game.prototype[model+"Manager"] = argument;
			}
		}

		return Game;
	}
);